<template>
  <div>
    <div class="pay_box">
      <el-form>
        <el-form-item label="接诊日期">
          <el-date-picker
            v-model="form.startTime"
            class="pay_date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="开始时间"
          ></el-date-picker>----
          <el-date-picker
            style="marigin-left:4%;"
            v-model="form.endTime"
            class="pay_date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="结束时间"
          ></el-date-picker>
          <el-button type="primary" circle icon="el-icon-search" @click="getChartTable(-1)"></el-button>
          <el-button type="primary" style="float:right;" @click="exportExcel()">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="pay_box">
      <table class="table-box">
        <thead>
          <tr>
            <th style="text-align:center;font-size:18px;" colspan="10">医生接诊统计报表</th>
          </tr>
          <tr>
            <th>接诊医生</th>
            <th>接诊人次</th>
            <th>总金额</th>
            <th>实验室检查</th>
            <th>辅助检查</th>
            <th>治疗</th>
            <th>处方</th>
            <th>材料</th>
            <th>其他</th>
            <th>诊金</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item,index) in tabList" :key="index">
            <td>{{item.doctorName}}</td>
            <td>{{item.receptionPersonCount}}</td>
            <td>￥{{item.singleTotalMoney}}</td>
            <td>￥{{item.checkMoney}}</td>
            <td>￥{{item.assistMoney}}</td>
            <td>￥{{item.adviceMoney}}</td>
            <td>￥{{item.prescriptionMoney}}</td>
            <td>￥{{item.materialMoney}}</td>
            <td>￥{{item.othersMoney}}</td>
            <td>￥{{item.registerMoney}}</td>
          </tr>
          <tr>
            <td>合计</td>
            <td>{{orderDayCount.totalReceptionPersonCount}}</td>
            <td>￥{{orderDayCount.totalMoney}}</td>
            <td>￥{{orderDayCount.totalCheckMoney}}</td>
            <td>￥{{orderDayCount.totalAssistMoney}}</td>
            <td>￥{{orderDayCount.totalAdviceMoney}}</td>
            <td>￥{{orderDayCount.totalPrescriptionMoney}}</td>
            <td>￥{{orderDayCount.totalMaterialMoney}}</td>
            <td>￥{{orderDayCount.totalOthersMoney}}</td>
            <td>￥{{orderDayCount.totalRegisterMoney}}</td>
          </tr>
        </tbody>
      </table>
      <br />
      <!-- <pager v-model="pager" @change-pagenum="getChartTable"></pager> -->
    </div>
  </div>
</template>
<script>
import Excel from "@/_js/excel.js";
export default {
  data() {
    return {
      form: {
        startTime: "",
        endTime: ""
      },
      orderDayCount: {
        totalAdviceMoney: "",
        totalAssistMoney: "",
        totalCheckMoney: "",
        totalMaterialMoney: "",
        totalMoney: "",
        totalOthersMoney: "",
        totalPrescriptionMoney: "",
        totalReceptionPersonCount: 0,
        totalRegisterMoney: ""
      },
      showDay: false,
      pager: { pageSize: 10, pageNum: 1, total: 0 },
      tabList: []
    };
  },
  mounted() {
    this.form.startTime = this.getDate();
    this.form.endTime = this.getNewDate();
    this.getChartTable();
  },
  methods: {
    getChartTable() {
      let th = this;
      th.showLoading();
      let j = Object.assign(th.form, th.pager);
      th.$api
        .doctorReception(j)
        .then(res => {
          if (res.executed) {
            th.tabList = res.data.doctorReceptionVOS;
            th.orderDayCount = {
              totalAdviceMoney: res.data.totalAdviceMoney,
              totalAssistMoney: res.data.totalAssistMoney,
              totalCheckMoney: res.data.totalCheckMoney,
              totalMaterialMoney: res.data.totalMaterialMoney,
              totalMoney: res.data.totalMoney,
              totalOthersMoney: res.data.totalOthersMoney,
              totalPrescriptionMoney: res.data.totalPrescriptionMoney,
              totalReceptionPersonCount: res.data.totalReceptionPersonCount,
              totalRegisterMoney: res.data.totalRegisterMoney
            };
            th.pager.total = res.dataBody.total;
            th.showLoading(false);
          } else {
            th.$message.error(res.message);
            th.showLoading(false);
          }
        })
        .catch(error => {
          th.showLoading(false);
        });
    },
    exportExcel() {
      const th = this;
      Excel(
        th.tabList,
        [
          { key: "doctorName", name: "接诊医生" },
          { key: "receptionPersonCount", name: "接诊人次" },
          { key: "singleTotalMoney", name: "总金额" },
          { key: "checkMoney", name: "实验室检查" },
          { key: "assistMoney", name: "辅助检查" },
          { key: "adviceMoney", name: "治疗" },
          { key: "prescriptionMoney", name: "处方" },
          { key: "materialMoney", name: "材料" },
          { key: "othersMoney", name: "其他" },
          { key: "registerMoney", name: "诊金" }
        ],
        "医生接诊统计报表"
      );
    }
  }
};
</script>
<style lang="scss" scoped>
.pay_box {
  margin-top: 10px;
  display: inline-block;
  width: 100%;
  overflow-x: auto;
  .table-box {
    min-width: 600px;
    font-size: 12px;
  }
}
.pay_date {
  width: 10% !important;
  margin-right: 1%;
}
</style>